package com.ambulance.project.manager.service.impl;

import java.util.List;

import com.ambulance.common.exception.CustomException;
import com.ambulance.project.manager.domain.BizDepart;
import com.ambulance.project.manager.utils.MgtCommonUtil;
import com.ambulance.project.manager.utils.MgtUserLoginResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ambulance.project.manager.mapper.BizDriverMapper;
import com.ambulance.project.manager.domain.BizDriver;
import com.ambulance.project.manager.service.IBizDriverService;

/**
 * 司机管理Service业务层处理
 *
 * @author zr
 * @date 2020-05-12
 */
@Service
public class BizDriverServiceImpl implements IBizDriverService
{
    @Autowired
    private BizDriverMapper bizDriverMapper;
    @Autowired
    private MgtCommonUtil mgtCommonUtil;
    /**
     * 查询司机管理
     *
     * @param driverID 司机管理ID
     * @return 司机管理
     */
    @Override
    public BizDriver selectBizDriverById(Long driverID)
    {
        return bizDriverMapper.selectBizDriverById(driverID);
    }

    /**
     * 查询司机管理列表
     *
     * @param bizDriver 司机管理
     * @return 司机管理
     */
    @Override
    public List<BizDriver> selectBizDriverList(BizDriver bizDriver)
    {
        final MgtUserLoginResult mgtUserLoginResult = mgtCommonUtil.getMgtUserLoginResult();
        bizDriver.setUid(new Long(mgtUserLoginResult.getUid()));
        return bizDriverMapper.selectBizDriverList(bizDriver);
    }

    /**
     * 新增司机管理
     *
     * @param bizDriver 司机管理
     * @return 结果
     */
    @Override
    public int insertBizDriver(BizDriver bizDriver)
    {
        final MgtUserLoginResult mgtUserLoginResult = mgtCommonUtil.getMgtUserLoginResult();
        bizDriver.setUid(new Long(mgtUserLoginResult.getUid()));
        return bizDriverMapper.insertBizDriver(bizDriver);
    }

    /**
     * 修改司机管理
     *
     * @param bizDriver 司机管理
     * @return 结果
     */
    @Override
    public int updateBizDriver(BizDriver bizDriver)
    {
        return bizDriverMapper.updateBizDriver(bizDriver);
    }

    /**
     * 批量删除司机管理
     *
     * @param driverIDs 需要删除的司机管理ID
     * @return 结果
     */
    @Override
    public int deleteBizDriverByIds(Long[] driverIDs)
    {
        return bizDriverMapper.deleteBizDriverByIds(driverIDs);
    }

    /**
     * 删除司机管理信息
     *
     * @param driverID 司机管理ID
     * @return 结果
     */
    @Override
    public int deleteBizDriverById(Long driverID)
    {
        return bizDriverMapper.deleteBizDriverById(driverID);
    }

    @Override
    public int freeze(Long driverID) {
        final BizDriver bizDriver = bizDriverMapper.selectBizDriverById(driverID);
        if(bizDriver.getStatus().equals(1)){
            throw new CustomException("该用户已被冻结,请勿重复点击");
        }
        return  bizDriverMapper.freeze(driverID);
    }
}
